<?php

/** Error reporting */
error_reporting(0);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');

define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

/** Include PHPExcel */
require_once dirname(__FILE__) . '/library/PHPExcel/Classes/PHPExcel/IOFactory.php';

$data = $_POST;
$error = array();

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);

switch ($data['type_data']) {
    case 'colors':
        $i = 1;
        foreach ($data['data_options'] as $option) {
            $objPHPExcel->getActiveSheet()->SetCellValue('A' . $i, $option[0]);
            $objPHPExcel->getActiveSheet()->SetCellValue('B' . $i, $option[1]);
            $i++;
        }
        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        $objWriter->save("colors_options.xlsx");
        break;
    case 'sizes':
        $i = 1;
        foreach ($data['data_options'] as $option) {
            $objPHPExcel->getActiveSheet()->SetCellValue('A' . $i, $option[0]);
            $objPHPExcel->getActiveSheet()->SetCellValue('B' . $i, $option[1]);
            $i++;
        }
        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        $objWriter->save("sizes_options.xlsx");
        break;
    case 'bullet_point':
        $i = 1;
        foreach ($data['data_options'] as $option) {
            $objPHPExcel->getActiveSheet()->SetCellValue('A' . $i, $option[0]);
            $i++;
        }
        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        $objWriter->save("bullet_options.xlsx");
        break;
    case 'keyword':
        $i = 1;
        foreach ($data['data_options'] as $option) {
            $objPHPExcel->getActiveSheet()->SetCellValue('A' . $i, $option[0]);
            $i++;
        }
        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        $objWriter->save("keyword_options.xlsx");
        break;
}
